/**
 * Created by renzhiqiang on 17/4/25.
 */
import { notification, Modal } from 'antd';
import * as User from './User';

const openNotice = (type, message, desc) => {
  notification[type] ({
    message: message,
    description: desc
  });
};
const openModal = (type, title, msg) => {
  Modal[type]({
    title: title,
    content: msg,
    okText: '关闭'
  });
};
window.queryApiInitPageSize = 10;
const parseParams = (data) => {
  let params = '';

  if (data) {
    for (var o in data) {
      if (data[o] !== null && data[o] !== undefined && data[o] !== '') {

        if (typeof data[o] === 'object' && data[o] instanceof Array && data[o].length > 0) {
          if (typeof data[o][0] === 'object') {
            params += (o + '=' + JSON.stringify(data[o]) + '&')
          } else {
            for (var i = 0; i < data[o].length; i++) {
              params += (o + '=' + data[o][i] + '&')
            }
          }
        } else {
          params += (o + '=' + data[o] + '&')
        }
      }
    }
  }

  if (params.length > 0) {
    params = params.substr(0, params.length - 1);
    //params = '?'+params+'_dc='+Math.random();
  }
  /*else{
   params = '?_dc='+Math.random();
   }*/
  return decodeURI(params);
};
// 项目路径
const config = {
  requestPath: 'http://localhost:63343/dvaTest/json/'
};
module.exports = {
  User,
  config,
  openModal,
  openNotice,
  parseParams
}
